package cn.gr.crawl.net;

import java.io.IOException;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

/**
 * @Description: TODO 
 * @author: henry.Tang   
 * @date:2012-5-11 下午01:01:24  
 * @version 0.1
 */
public abstract class GRDataServiceAbstract{
    private GetMethod getMethod;    
    public GetMethod getGetMethod() {
        return getMethod;
    }
    public void setGetMethod(GetMethod getMethod) {
        this.getMethod = getMethod;
    }


    /**  
     * 
     * @Description http连接是否正确
     * @param url 连接URL
     * @return int 返回的状态
     * @throws IOException 
     * @throws HttpException 
     */
    public int httpConnectionStatus(String url) throws HttpException, IOException {
        HttpClient httpClient = new HttpClient();
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        //url = "https://www.google.com/accounts/ClientLogin?accountType=HOSTED_OR_GOOGLE&Email=hufuli@163.com&Passwd=bb1314520&service=reader&source=J-MyReader-1.0";
        GetMethod getMethod = new GetMethod(url);
        getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);
        getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());
        int statusCode = httpClient.executeMethod(getMethod);
        setGetMethod(getMethod);
        return statusCode;
    }
}
